package com.quanxiaoha.weblog.admin.validator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;

/**
 * @author: 犬小哈
 * @url: www.quanxiaoha.com
 * @date: 2025-01-20
 * @description: 条件验证注解，用于当某个条件成立时才验证指定字段
 **/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = ConditionalValidator.class)
@Documented
public @interface ConditionalValidation {
    
    String message() default "条件验证失败";
    
    Class<?>[] groups() default {};
    
    Class<? extends Payload>[] payload() default {};
    
    /**
     * 条件字段名
     */
    String conditionField();
    
    /**
     * 条件字段的期望值
     */
    String conditionValue() default "true";
    
    /**
     * 需要验证的字段名数组
     */
    String[] requiredFields();
    
    /**
     * 验证失败时的错误信息数组，与requiredFields一一对应
     */
    String[] messages();
}
